package com.example.binpacking.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.binpacking.model.Interviewer;
import com.example.binpacking.model.Result;
import com.example.binpacking.service.InterviewerService;
import com.example.binpacking.util.JWTUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/pelicanpsyc")
public class InterviewerController {
    @Autowired
    private InterviewerService interviewerService;

//    @PostMapping  ("/login")
//    public Result login(@RequestParam BigDecimal loginid, @RequestParam String password, @RequestParam String usertype) {
//        Map<String, Object> map = new HashMap<>();
//        Interviewer interviewer = interviewerService.login(loginid,password,usertype);
//        //登陆成功
//        if(interviewer!=null){
//            System.out.println(interviewer.getLoginid());
//            map.put("loginid",interviewer.getLoginid());
//            map.put("usertype",interviewer.getUsertype());
//            String token = JWTUtil.createUserTypeToken(usertype);
//            System.out.println(token);
//            map.put("token",token);
//        }
//        return Result.success(map);
//    }
//@PostMapping  ("/login")
//public Result login(@RequestBody Interviewer interviewer) {
//    Map<String, Object> map = new HashMap<>();
//    Interviewer i = interviewerService.login(interviewer);
//    //登陆成功
//    if(interviewer!=null){
//        map.put("loginid",i.getLoginid());
//        map.put("usertype",i.getUsertype());
//        String token = JWTUtil.createUserTypeToken(i.getUsertype());
//        System.out.println(token);
//        map.put("token",token);
//    }
//    return Result.success(map);
//}

//    @PostMapping("/api/login")
//    public Result login(@RequestParam BigDecimal loginid, @RequestParam String password) {
//        String strValue = loginid.toString();
//        String token = JWTUtil.createToken(strValue,password);
//        String encryptedPassword = DigestUtils.md5Hex(password);
//        List<Interviewer> list = interviewerService.findByLoginIdAndPassword(loginid,encryptedPassword);
//
//        HashMap map = new HashMap<>();
//        map.put("token",token);
//        map.put("data",list);
//        return Result.success(map);
//    }


    @ApiOperation("基础分页功能")
    @GetMapping("/api/page")
    public IPage<Interviewer> getUsers(
            @RequestParam(name = "page", defaultValue = "1") int currentPage,
            @RequestParam(name = "size", defaultValue = "1") int pageSize) {
        return interviewerService.getInterviewerByPage(currentPage, pageSize);
    }

}
